home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / docs / mags / woa4.lha / WORLD4 / Features / arexx / slideshow.rexx < prev   
Encoding:
OS/2 REXX Batch file  |  1999-08-12  |  16.1 KB  |  357 lines

  1. /*  This is a simple multimedia slideshow program.  Requires Multiview. */
  2.  
  3.  
  4. /* the following section of code checks to see if the library is open,
  5.    and it attempts to open the library if it is not already open.  If it
  6.    cannot open the library, it will not continue, since the program will
  7.    fail without the library functions available. */
  8. if ~show('l','rexxbgui.library') then do
  9.     /* the numeric parameters for addlib are priority and offset. Priority is
  10.     somewhat arbitrary (between -/+ 100), and offset is specific to each
  11.     library, although I often see -30 used.*/
  12.    if ~addlib('rexxbgui.library',0,-30) then do
  13.       exit(20)
  14.        /* 20 is an error code; you can exit with any value, or none at all. */
  15.    end
  16. end
  17.  
  18. if ~show('l','rexxsupport.library') then do
  19.    if ~addlib('rexxsupport.library',0,-30) then do
  20.       exit(20)
  21.        /* 20 is an error code; you can exit with any value, or none at all. */
  22.    end
  23. end
  24.  
  25.  
  26. /* this section of code loads the settings for the slideshow. */
  27. /* configfile is the name of the file used to store the slideshow settings and
  28.    names of the pictures.*/
  29. configfile="slideshow.prefs"
  30. shows. = ''           /* clear out the entire stem. */
  31. texts. = ''           /* clear out the entire stem. */
  32. curShowIndex = 0      /* keeps track of selection in list of slides */
  33. shows.count = 0
  34. newpath = ""          /* used by the file requester.  see the add button.*/
  35. if exists(configfile) then do
  36.     /* This will only parse the file for content if it exists. */
  37.     open('prefsfile',configfile,'R')
  38.     i=0
  39.     do while EOF('prefsfile')=0
  40.         /* read the filename of each "slide" */
  41.         curshow = readln('prefsfile')
  42.         if length(curshow)>0 then shows.i = curshow
  43.         /* read the title, description, and date for each slide */
  44.         curtitle = readln('prefsfile')
  45.         if length(curtitle)>0 then texts.i.title = curtitle
  46.         curdescription = readln('prefsfile')
  47.         if length(curdescription)>0 then texts.i.description = curdescription
  48.         curdate = readln('prefsfile')
  49.         if length(curdate)>0 then texts.i.date = curdate
  50.         i = i+1
  51.         end
  52.     shows.count = i-1  /* count of entries */
  53.     close('prefsfile')
  54.     end
  55.  
  56. call bguiopen() /* causes error 12 if it did not work */
  57. /* supply a second argument for a '0' return code instead of an ARexx
  58.    error */
  59.  
  60. /* the following "signal" statements trap errors */
  61. signal on syntax /* important: bguiclose() MUST be called */
  62. signal on halt
  63. signal on break_c
  64.  
  65.  
  66. FixMinSize=bguilayout(LGO_FixMinWidth,1,LGO_FixMinHeight,1)
  67.  
  68. /* GUI function calls for creating the primary intreface window */
  69. /* All the "GUI" lines are segments of the user interface description.
  70.    Each of these entries is combined into groups, and then into one group
  71.    at the end (called GUIcombined).  The parameters for each of these
  72.    functions are described in the BGUI documentation.  Basically, there are
  73.    GUI elements, groups, and layouts described. in all this.  Note that the
  74.    GUI elements, such as the listview, buttons, and string text field all
  75.    have a name.  BGUI creates a branch on the ubiquitous "obj." stem, based
  76.    on these set names.  */
  77. if (shows.count = 0) then do            /* if the list is empty, don't put
  78.                                            the empty stem down. */
  79.     GUIshowlist=bguilistview('listv',,,'S')
  80.     end
  81. else
  82.     GUIshowlist=bguilistview('listv',,'SHOWS','S')  /* list is not empty. */
  83.  
  84. GUIlistcontrols=bguivgroup(bguibutton('add','_Add')bguibutton('drp','_Drop')bguibutton('up','_Up')bguibutton('down','D_own'),0,,,'W')FixMinSize
  85. GUItop=bguihgroup(GUIlistcontrols||GUIshowlist,0,,,)
  86. GUItitle=bguistring('title','Title:','',80)
  87. GUIdate=bguistring('date','Date:','12/31/1999',11)bguilayout(LGO_FixMinHeight,1,LGO_FixWidth,120)
  88. GUIcaption=bguihseparator('Description')bguilayout(LGO_FixMinHeight,1)
  89. GUIdescription=bguistring('desc',,'',500)bguilayout(LGO_FixMinHeight,1)
  90. GUIShow=bguihgroup(bguivarspace(50)bguibutton('show','_Show')bguilayout(LGO_FixMinHeight,1)bguivarspace(50))
  91. GUImiddle=bguihgroup(GUItitle||Guidate,0,,,'H')bguilayout(LGO_FixMinHeight,1)
  92. GUIbottom=bguivgroup(GUIcaption||GUIdescription||GUIShow,0,,,)bguilayout(LGO_FixMinHeight,1)
  93.  
  94. /* this last one is where they are all combined. */
  95. GUIcombined=bguivgroup(GUItop||GUImiddle||GUIbottom,0)
  96.  
  97. /* Disable the "drop" button initially; wait until something is selected. */
  98. call bguiset(obj.drp,,GA_Disabled,1)
  99.  
  100. /* Open the main window.
  101.    parameters:    title, object, %wide, %high */
  102. mainwindowObj=bguiwindow('Slide Show',GUIcombined,40,70)
  103. if bguiwinopen(mainwindowObj)=0 then bguierror(12)
  104.  
  105. /* "id" is another ubiquitous BGUI stem variable; it identifies which BGUI
  106.    object responded to an event. */
  107. id=0
  108.  
  109. /* this is the main program loop.  Bguiwinwaitevent idles until the window
  110.    receives an event.  The loop exits if the window is closed. */
  111. do while bguiwinwaitevent(mainwindowObj,'ID')~=id.winclose
  112.    select
  113.        /*** Description Field ***/
  114.       when id=id.desc then do
  115.           /* update the stem "shows" at the current index with the current
  116.              description.*/
  117.          texts.curShowIndex.description = bguiget(obj.desc,STRINGA_TextVal)
  118.       end
  119.        /*** Title Field ***/
  120.       when id=id.title then do
  121.           /* update the stem "shows" at the current index with the current
  122.              title; note that title in the "shows" title does not overlap
  123.              with the "id" stem title. */
  124.          texts.curShowIndex.title = bguiget(obj.title,STRINGA_TextVal)
  125.       end
  126.        /*** Date Field ***/
  127.       when id=id.date then do
  128.           /* update the stem "shows" at the current index with the current
  129.              date; note that date in the "shows" date does not overlap
  130.              with the "id" stem date. */
  131.          texts.curShowIndex.date = bguiget(obj.date,STRINGA_TextVal)
  132.       end
  133.        /*** Slide List ***/
  134.       when id=id.listv then do
  135.           /* when the selection changes in the list view, it changes the text
  136.              description, title, and date, based on the "shows" stem contents
  137.              at the position 'curShowIndex,' which is read as the index into
  138.              the list view.  Also enable the drop button. */
  139.          curShowIndex= bguiget(obj.listv,'LISTV_LastClickedNum')
  140.          call bguiset(obj.desc,mainwindowObj,STRINGA_TextVal,texts.curShowIndex.description)
  141.          call bguiset(obj.title,mainwindowObj,STRINGA_TextVal,texts.curShowIndex.title)
  142.          call bguiset(obj.date,mainwindowObj,STRINGA_TextVal,texts.curShowIndex.date)
  143.          call bguiset(obj.drp,mainwindowObj,GA_Disabled,0)
  144.       end
  145.        /*** Add Button ***/
  146.       when id=id.add then do
  147.             /*newfile identifies the image file as the return value from the
  148.               file requester; pragma finds the current directory name. Note
  149.               that checking the length of newpath allows the file requester
  150.               to be opened without the current directory given; BGUI's file
  151.               requester will remember the last directory automatically. */
  152.             if (length(newpath) = 0) then do
  153.              newpath = bguifilereq(pragma('D'),'Choose an image file',mainwindowObj,'REJECTICONS')
  154.              end
  155.          else do
  156.              newpath = bguifilereq(,'Choose another image file',mainwindowObj,'REJECTICONS')
  157.              end
  158.           if (length(newpath)>0) then do /* a filename was given. */
  159.               /* add the new entry to the listview, enable the drop button,
  160.                  and update description, title, and date fields, as well as
  161.                  the "shows" stem. 'T' option puts at end of list. */
  162.             call bguilistvaddentry(obj.listv,mainwindowObj,newpath,,'T')
  163.             /* this gathers the saved date of the file and formats it.  If
  164.                you prefer a more European date format, replace USA with
  165.                European. The output of the AmigaDos command is stored in
  166.                a text file.  Some file  manipulation is necessary
  167.                to read the results of 'list.'*/
  168.             address command
  169.             tempfile = "ram:SlideshowOutput"
  170.             /* list gets us the current date.  */
  171.             'list "'newpath'" LFORMAT %d >'tempfile
  172.             address
  173.             open('outputfile',tempfile,'R')
  174.             newdat = Readln('outputfile')
  175.             close('outputfile')
  176.             address command
  177.             'delete 'tempfile' >nil:'
  178.             address
  179.             /* clear some text fields, set date field to date of file. */
  180.             call bguiset(obj.listv,mainwindowObj,LISTV_Deselect,curShowIndex)
  181.             call bguiset(obj.date,mainwindowObj,STRINGA_TextVal,newdat)
  182.                 curShowCount= bguiget(obj.listv,'LISTV_NumEntries')-1
  183.             texts.curShowCount.date = newdat
  184.             curShowIndex = curShowCount
  185.             call bguiset(obj.listv,mainwindowObj,ListV_Select,curShowCount)
  186.             call bguiset(obj.desc,mainwindowObj,STRINGA_TextVal,"")
  187.             call bguiset(obj.title,mainwindowObj,STRINGA_TextVal,"")
  188.             call bguiset(obj.drp,mainwindowObj,GA_Disabled,0)
  189.              end /* file was chosen */
  190.       end
  191.        /*** Drop Button ***/
  192.       when id=id.drp then do
  193.           /* shift descriptions, titles, date up one, unless at end. */
  194.             curShowIndex= bguiget(obj.listv,'LISTV_LastClickedNum')
  195.             curShowCount= bguiget(obj.listv,'LISTV_NumEntries')-1
  196.             if curShowIndex < curShowCount then do
  197.                 i = curShowIndex
  198.                 do while i < curShowCount   /* repeat for remaining slides */
  199.                     nextShowIndex = i + 1
  200.                     texts.i.title = texts.nextShowIndex.title
  201.                     texts.i.description = texts.nextShowIndex.description
  202.                     texts.i.date = texts.nextShowIndex.date
  203.                     i = i + 1
  204.                     end /* loop on shifting remaining entries up */
  205.                 end /* must shift remaining entries up. */
  206.           /* remove selected entry.  */
  207.          call bguilistvcommand(obj.listv,mainwindowObj,'remselected')
  208.             call bguiset(obj.listv,mainwindowObj,ListV_Select,curShowCount)
  209.          if bguiget(obj.listv,'LISTV_NumEntries')=0 then,
  210.             call bguiset(obj.drp,mainwindowObj,GA_Disabled,1)
  211.       end
  212.        /*** Up Button ***/
  213.       when id=id.up then do
  214.           call bguilistvgetentries(obj.listv, curslide, 'S')
  215.           call bguilistvgetentries(obj.listv, shows,'A')
  216.           matchID =0
  217.           do i=0 to shows.count
  218.               if shows.i = curslide.0 then do
  219.                   /* a match in the list was found for the selected entry */
  220.                   /* curslide is re-used from above as a stem to hold the
  221.                      swap values of the text fields. */
  222.                   matchID = i-1
  223.                   if matchID >= 0 then do
  224.                       /* swap the two entries */
  225.                       curslide.1 = shows.matchID
  226.                       shows.matchID = curslide.0
  227.                       shows.i = curslide.1
  228.                       /* now swap all the text values. */
  229.                       curslide.title = texts.matchID.title
  230.                       curslide.date = texts.matchID.date
  231.                       curslide.description = texts.matchID.description
  232.                       texts.matchID.title = texts.i.title
  233.                       texts.matchID.date = texts.i.date
  234.                       texts.matchID.description = texts.i.description
  235.                       texts.i.title =curslide.title
  236.                       texts.i.date = curslide.date
  237.                       texts.i.description = curslide.description
  238.                       i = shows.count /* stops the loop */
  239.                       end /* end of match not first in list. */
  240.                   end     /* end of match found */
  241.               end         /* end of loop */
  242.           /* clear all the entries. */
  243.           call bguilistvcommand(obj.listv,mainwindowObj,'clear')
  244.           /* add them back in, with the swap. */
  245.           do i=0 to shows.count
  246.               /* if it is the selected one, re-select it. */
  247.               if i=matchID then bguilistvaddentry(obj.listv,, shows.i,'T','S')
  248.               else bguilistvaddentry(obj.listv,, shows.i,'T')
  249.               end
  250.           call bguilistvcommand(obj.listv,mainwindowObj,'refresh')
  251.           end
  252.        /*** Down Button ***/
  253.       when id=id.down then do
  254.           call bguilistvgetentries(obj.listv, curslide, 'S')
  255.           call bguilistvgetentries(obj.listv, shows,'A')
  256.           matchID =0
  257.           do i=0 to shows.count
  258.               if shows.i = curslide.0 then do
  259.                   /* a match in the list was found for the selected entry */
  260.                   /* curslide is re-used from above as a stem to hold the
  261.                      swap values of the text fields. */
  262.                   matchID = i + 1
  263.                   if matchID < shows.count then do
  264.                       /* swap the two entries */
  265.                       curslide.1 = shows.matchID
  266.                       shows.matchID = curslide.0
  267.                       shows.i = curslide.1
  268.                       /* now swap all the text values. */
  269.                       curslide.title = texts.matchID.title
  270.                       curslide.date = texts.matchID.date
  271.                       curslide.description = texts.matchID.description
  272.                       texts.matchID.title = texts.i.title
  273.                       texts.matchID.date = texts.i.date
  274.                       texts.matchID.description = texts.i.description
  275.                       texts.i.title =curslide.title
  276.                       texts.i.date = curslide.date
  277.                       texts.i.description = curslide.description
  278.                       i = shows.count /* stops the loop */
  279.                       end /* end of match not last in list. */
  280.                   end     /* end of match found */
  281.               end         /* end of loop */
  282.           /* clear all the entries. */
  283.           call bguilistvcommand(obj.listv,mainwindowObj,'clear')
  284.           /* add them back in, with the swap. */
  285.           do i=0 to shows.count
  286.               /* if it is the selected one, re-select it. */
  287.               if i=matchID then bguilistvaddentry(obj.listv,, shows.i,'T','S')
  288.               else bguilistvaddentry(obj.listv,, shows.i,'T')
  289.               end
  290.           call bguilistvcommand(obj.listv,mainwindowObj,'refresh')
  291.           end
  292.        /*** Show! Button ***/
  293.       when id=id.show then do
  294.           if shows.count >0 then call ShowSlides
  295.           end
  296.        /*** Nothing happened ***/
  297.       when id=id.wininactive then nop
  298.        /*** Window closed - drops out of while loop from the top. ***/
  299.       when id=id.winclose then nop
  300.       otherwise nop
  301.    end  /* end of select list */
  302. end     /* end of while loop. */
  303. rc=0
  304. call exitfn() /* user has closed window, signifies end of program. */
  305.  
  306.  
  307. /* reports errors in the code. */
  308. syntax:
  309. /* errortext prints various error messages based on numeric codes. */
  310. if rc~=0 then say '+++ ['rc']' errortext(rc) 'at line' sigl
  311. call bguiclose()
  312. exit 0
  313.  
  314. /* separate message if the user halts the program with ctrl-c or some other
  315.    means. */
  316. break_c:
  317. halt:
  318. rc=0        /* rc is a built-in variable for return code in ARexx */
  319. say '+++ Break at line' sigl
  320. signal syntax
  321.  
  322. /* this is a precursor to the exit routine;
  323.    it saves settings to the prefs file on exit. */
  324. exitfn:
  325. counter=bguilistvgetentries(obj.listv,shows,'A')
  326.     open('prefsfile',configfile,'W')
  327.     do i = 0 to shows.count
  328.         /* write the "slide" filename to the file. */
  329.         if (length(shows.i)>0) then do
  330.             writeln('prefsfile',shows.i)
  331.             /* read the title, description, and date for each slide */
  332.             writeln('prefsfile',texts.i.title)
  333.             writeln('prefsfile',texts.i.description )
  334.             writeln('prefsfile',texts.i.date)
  335.             end /* shows has length */
  336.         end
  337.     close('prefsfile')
  338. call bguiclose()
  339. exit 0
  340.  
  341. /* this small function does all the display and sound. */
  342. /* be sure to change multiview in both places if you want to change to
  343.    another program.  The break statement stops the first multiview call
  344.    so that countless copies are not running at once. */
  345. ShowSlides:
  346. max = shows.count -1
  347. address command
  348. do i=0 to max
  349.     'run multiview "'shows.i'" >nil:'
  350.     'say -n -m -p100 'texts.i.title'.'
  351.     'say -n -m -p100 was take n on 'texts.i.date
  352.     'say -n -m -p100 'texts.i.description
  353.     'status command multiview >pipe:'
  354.     'break >NIL: <PIPE: ALL ?'
  355.     end
  356. address
  357. return